package tests;
/**
 * @author Taylor Zielske
 * @version Nov 27, 2011
 */
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;

import java.io.File;
import java.util.ArrayList;
import java.util.Date;

import org.junit.Before;
import org.junit.Test;

import papers.Manuscript;
import papers.Review;
import users.Author;
import users.Reviewer;

public class TestManuscript {
	/**
	 * The review
	 */
	private Manuscript my_manu;
	
	/**
	 * The reviewer
	 */
	private Author my_author;
	
	/**
	 * The reviewer name
	 */
	private String author_name = "Testing_author";
	
	/**
	 * The date
	 */
	private Date my_date = new Date();
	
	/**
	 * The review file
	 */
	private File my_manuFile = new File("manu.txt");
	
	
	/**
	 * Initializes the review
	 */
	@Before
	public void setUp() {
		my_author = new Author(author_name);
		
		my_manu = new Manuscript(my_author, my_date, "my paper", my_manuFile);

	}
	
	/**
	 * Tests the create manuscript constructor
	 */
	@Test
	public void testCreateManuscript() {
		assertEquals("Paper names are equal", 
				my_manu.getPaperName(), "my paper");
		assertEquals("Paper file is the same", 
				my_manu.getPaper(), my_manuFile);
		assertEquals("Date is the same", 
				my_manu.getSubmissionDate(), my_date);
		assertEquals("Author is the same", 
				my_manu.getAuthor(), my_author);
	}

	/**
	 * Tests the set status method
	 */
	@Test
	public void testSetStatus() {
		my_manu.setStatus(Manuscript.Status.YES);
		assertSame("Rating is the same for one review", 
				Manuscript.Status.YES, my_manu.getStatus());	
	}
	/**
	 * Tests the set reviewer method
	 */
	@Test
	public void testSetReviewer() {
		Reviewer reviewer = new Reviewer("tay");
		Review r = new Review(reviewer, my_date, new File("test.txt"));
		my_manu.addReviewer(reviewer);
		if(my_manu.getReviewers().contains(reviewer)){
			my_manu.addReview(r);
		}
		assertTrue("Contains reviewer", my_manu.getReviewers().contains(reviewer));
		assertTrue("Contains review", 
				my_manu.getReviews().contains(r));		
	}
	
	/**
	 * Tests the set reviewers method
	 */
	@Test
	public void testSetReviewers() {
		Reviewer reviewer1 = new Reviewer("tay");
		Reviewer reviewer2 = new Reviewer("tay");
		
		ArrayList<Reviewer> r_list = new ArrayList<Reviewer>();
		r_list.add(reviewer1);
		r_list.add(reviewer2);
		
		assertEquals("Size of the list is not zero", 
				my_manu.getReviewers().size(), 0);
		
		my_manu.setReviewers(r_list);
		assertEquals("Size of the list is not two", 
				my_manu.getReviewers().size(), 2);
		assertTrue("Contains reviewer", my_manu.getReviewers().contains(reviewer1));
		assertTrue("Contains reviewer", my_manu.getReviewers().contains(reviewer2));
	}
}
